package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/login")
public class LoginServlet extends HttpServlet{

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// 1.获取参数
		String username = req.getParameter("username");
		String userpwd = req.getParameter("userpwd");
		// 2.设置resp
		resp.setContentType("text/html;charset=utf-8");
		resp.setCharacterEncoding("utf-8");
		PrintWriter out = resp.getWriter();
		// 3.判断用户名和密码
		if ("root".equals(username) && "123".equals(userpwd)) {
			out.write("登录成功");
		}else {
			out.write("登录失败");
		}
		out.flush();
	}
}
